package com.tools.commons.response;


import com.tools.commons.exceptions.GlobalException;
import com.tools.commons.utils.StringUtils;
import org.slf4j.Logger;

/**
 * @author wangminggen
 */
public interface Assert {
    Logger getLog();

    default void assertNotNull(Object obj, String... args) {
        if (getLog().isDebugEnabled()) {
            getLog().debug("AssertNotNull [ {} ]", obj);
        }
        if (obj == null) {
            throw newException(args);
        }
    }

    default void assertNotNull(Object obj) {
        if (obj == null) {
            throw newException("不能为空");
        }
    }

    default void assertNotBlank(String str, String... args) {
        if (getLog().isDebugEnabled()) {
            getLog().debug("AssertNotBlank [ {} ]", str);
        }
        if (StringUtils.isBlank(str)) {
            throw newException(args);
        }
    }

    default void assertNotFalse(Boolean flag, String... args) {
        if (getLog().isDebugEnabled()) {
            getLog().debug("AssertNotFalse [ {} ]", flag);
        }
        if (!flag) {
            throw newException(args);
        }
    }

    default void assertNotTrue(Boolean flag, String... args) {
        if (getLog().isDebugEnabled()) {
            getLog().debug("AssertNotTrue [ {} ]", flag);
        }
        if (flag) {
            throw newException(args);
        }
    }

    default void throwException(String... args) {
        throw newException(args);
    }

    ResponseCode getResponseCode();

    default GlobalException newException(String... args) {
        return new GlobalException(getResponseCode(), args);
    }
}
